
var Random = null

function createPets(){
    let data = []

    for(let i = 0 ; i < 10; i++){
        data.push (Mock.mock({
            "name" : Random.cname(),
            "type" : Random.cname(),
            "kind" : Random.cname(),
            "intro" : Random.csentence(),
            "price" : Random.float(500,1000,2,2),
            "image" : Random.image(),
            "stock" : Random.integer(0,1000),
        }))
    }



    let json = {
        "data" : data,
        "code" : 200,
    }
    
    return json
}

function getKinds(){
    let data = []

    for(let i = 0; i < 8; i++){
        data.push(
            Mock.mock({
            "type" : Random.cname(),
            "image" : Random.image()})
        )
    }

    let json = {
        "data" : data,
        "code" : 200,
    }

    return json

}

function getPet(){
    let commentList = []

    for(let i = 0 ; i < 15; i++){
        let comment = Mock.mock({
            "avatar": Random.image(),
            "comment": Random.cparagraph(),
            "username" : Random.cname(),
            "date" : Random.datetime()
        })

        commentList.push(comment)
    }


    let data = Mock.mock({
        "name" : Random.cname(),
        "type" : Random.cname(),
        "kind" : Random.cname(),
        "intro" : Random.cparagraph(10),
        "price" : Random.float(500,1000,2,2),
        "image" : Random.image(),
        "stock" : Random.integer(0,1000),
        "commentList" : commentList
    })

    let json = {
        code : 200,
        msg : "获取成功",
        data: data,
    }

    return json
}

function init(Mock){
    Random = Mock.Random

    //获取所有关于这个类型的宠物
    Mock.mock(/http:\/\/localhost\/pet_all.php.*?/, 'get', createPets())

    //获取所有宠物类型
    Mock.mock('http://localhost/pet_kinds.php', 'get', getKinds())

    //获取这个宠物的信息
    Mock.mock(/http:\/\/localhost\/get_pet.php.*?/, 'get', getPet())
}